home *** CD-ROM | disk | FTP | other *** search
/ Maplin Electronics Catalogue 2001 Winter / Maplins Catalogue Winter 2001.iso / JScript / jshop.js < prev    next >
Text File  |  2001-11-20  |  3KB  |  118 lines

  1. // jshop.js JavaScript Development by Burgeonet.com
  2.  
  3. // ****Begin code section for catalog display****
  4.  
  5. // **Establish array variables. These must match the**
  6. // **catalog array construction in each page.**
  7.  
  8. var catNo = new Array(); // The catalog number
  9. var itemDesc = new Array(); // The item description
  10. var price = new Array(); // The item price
  11. var itemQty = new Array();
  12.  
  13. // ****Begin shared cookie functions****
  14.  
  15. // **Global expdate variable for cookies**
  16. // **Cookie is set to expire in 24 hours**
  17.  
  18. var expdate = new Date();
  19. expdate.setTime (expdate.getTime() + (28 * 24 * 60 * 60 * 1000)) // 28 days from now
  20.  
  21. // **Read cookie data.**
  22.  
  23. function getCookieData(name) {
  24.  var label = name + "="
  25.  var cStart = document.cookie.indexOf(label) 
  26.  var labelLen = label.length
  27.  var cLen = document.cookie.length
  28.  cStart += labelLen
  29.  var tempstr = document.cookie.substring(cStart,cLen)
  30.  var cEnd = tempstr.indexOf(";")
  31.          if (cEnd == -1) {
  32.              cEnd = document.cookie.length
  33.         }
  34.   return unescape(tempstr.substring(0,cEnd))
  35.  }
  36.  
  37. // **Write cookie data**
  38.  
  39. function setCookieData(name,value,expires) {
  40.         counter ++
  41.     document.cookie = name + "=" + counter + "@" + value + "; expires=" + expires + "; Path=" + "/"
  42. }
  43.  
  44. // **Kill cookie function. When the order is submitted**
  45. // **the cookie is killed via an event handler call.**
  46.  
  47. function killCookie(name) {
  48.  if (getCookieData(name)) {
  49.  document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT" + "; Path=" + "/"
  50.  cLen = orderString.length
  51.  countEnd = orderString.indexOf("@")
  52.  pointer = countEnd + 1
  53.  counter = orderString.substring(0,countEnd)
  54.  cookData = orderString.substring(pointer,cLen)
  55.  cookData = ""
  56.  counter = 0
  57.  history.go(0)
  58.  }
  59. }
  60.  
  61.  
  62. // ****End shared cookie functions****
  63.  
  64.  
  65. // ****Begin code section to update the cookie to ****
  66. // ****add items to the shopping cart cookie 'Scart'.****
  67.  
  68. // **Global variables.**
  69.  
  70. var counter = 0
  71. var cookData = ""
  72.  
  73. // **Extract current value of cookie when page loads **
  74. // **and store the values in the global variables.**
  75.  
  76. if (getCookieData("Scart")) {
  77.  
  78.  orderString = getCookieData("Scart")
  79.  cLen = orderString.length
  80.  countEnd = orderString.indexOf("@")
  81.  pointer = countEnd + 1
  82.  counter = orderString.substring(0,countEnd)
  83.  cookData = orderString.substring(pointer,cLen)
  84. }
  85.  
  86. // **Function to add an item to the shopping cart cookie.**
  87.  
  88. function addItem(num) {
  89.  
  90.  orderString = getCookieData("Scart")
  91.  cLen = orderString.length
  92.  countEnd = orderString.indexOf("@")
  93.  pointer = countEnd + 1
  94.  counter = orderString.substring(0,countEnd)
  95.  cookData = orderString.substring(pointer,cLen)
  96.  
  97.  a = eval("catNo[num]")
  98.  
  99.  addCart = '' + a + '`' + itemDesc[num] + '~' + price[num] + '½' + itemQty[num] + '^'
  100.  cookData += eval("addCart")
  101.  
  102.  if (confirm("Add  ( Qty " + itemQty[num] + " " + a + " " + itemDesc[num] + ' )  to shopping basket')) {
  103.   setCookieData("Scart", cookData, expdate.toGMTString())
  104. }
  105. }
  106.  
  107.  
  108. // ****End code section for updating the cookie.****
  109.  
  110.  
  111. // ****Debugging function to display cookie contents.****
  112.  
  113. function showMe() {
  114.  display = getCookieData("Scart");
  115. }
  116.  
  117.  
  118.